import 'package:flutter/material.dart';
import 'package:flutterproject/page/mine/children/assets/data/assets_detail_bean.dart';
import 'package:flutterproject/util/extension/extension_util.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/text/text_common.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

class ListWidget extends StatelessWidget {
  final String title;
  final List<AssetsDetailList> list;

  const ListWidget({super.key, required this.title, required this.list});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: Get.width,
      padding: MarginPaddingUtil.symmetric(vertical: 32),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(20.radius),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
            padding: MarginPaddingUtil.only(left: 42),
            child: TextCommon(
              "$title记录",
              size: 24.sp,
              fontWeight: FontWeight.bold,
              color: Color(0xFF414141),
            ),
          ),
          22.heightBox,
          Expanded(
            child: ListView.separated(
              padding: EdgeInsets.zero,
              shrinkWrap: true,
              itemCount: list.length ?? 0,
              separatorBuilder: (context, index) => Padding(
                padding: MarginPaddingUtil.symmetric(vertical: 22),
                child: Divider(
                  color: Color(0xFFE7E7E7),
                  height: 1.width,
                ),
              ),
              itemBuilder: (context, index) {
                return Padding(
                  padding: MarginPaddingUtil.symmetric(horizontal: 47),
                  child: Row(
                    children: [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          TextCommon(
                            "${list[index].opRemark}",
                            color: Color(0xFF414141),
                          ),
                          17.heightBox,
                          TextCommon(
                            DateFormat("yyyy-MM-dd HH:mm:ss").format(
                                DateTime.fromMillisecondsSinceEpoch(
                                    list[index].createTime ?? 0)),
                            size: 20.sp,
                            color: Color(0xFF707070),
                          ),
                        ],
                      ),
                      Spacer(),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          TextCommon(
                            "${list[index].opValue?.toStringAsFixed(2)}",
                            color: Color(0xFF414141),
                            size: 32.sp,
                            fontWeight: FontWeight.bold,
                          ),
                          17.heightBox,
                          TextCommon(
                            "变更后余额：${list[index].opAfter?.toStringAsFixed(2)}",
                            size: 20.sp,
                            color: Color(0xFF707070),
                          ),
                        ],
                      ),
                    ],
                  ),
                );
              },
            ),
          )
        ],
      ),
    );
  }
}
